-- You may have to change the parameter list to suit your configuration
-- NOTE: This button is a self contained operation of open, put,close.
-- You DO NOT have to open and close every time you get or put.
-- Just open once and start once, like when you open and close
-- your stack.
set the cursor to watch
get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
if it is not empty then
put "Error: "&&it&&" (See script of "put" button)"
end if
put the number of lines in the script of me into nl
repeat with i = 1 to nl
get line i of the script of me
get Serialhandler("put","A",it&return&numToChar(10))
end repeat
if it is not empty then
put "Error: "&&it
end if
get Serialhandler("close","A")
end mouseUp
-- part 10 (button)
-- low flags: 80
-- high flags: 8003
-- rect: left=187 top=306 right=324 bottom=223
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Get
----- HyperTalk script -----
on mouseUp
-- You may have to change the parameter list to suit your configuration
-- NOTE: This button is a self contained operation of open, get,close.
-- You DO NOT have to open and close every time you get or put.
-- Just open once and start once, like when you open and close
-- your stack.
set the hilite of me to true
set the cursor to watch
get SerialHandler("open","A",9600,8,none,1,"XON/XOFF")
set the visible of card field "got" to true
put empty into card field "got"
put "Click the mouse when done."
put "Characters received on the serial port will appear below:" &return&return into card field "got"
repeat while the mouse is up
get SerialHandler("get","A",60)
put it after card field "got"
end repeat
get SerialHandler("close","A")
set the visible of card field "got" to false
set the hilite of me to false
put empty into msg
hide msg
end mouseUp
-- part 11 (field)
-- low flags: 80
-- high flags: 0007
-- rect: left=18 top=32 right=285 bottom=481
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: got
-- part 12 (field)
-- low flags: 01
-- high flags: 0004
-- rect: left=281 top=289 right=325 bottom=465
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name:
-- part contents for card part 5
----- text -----
SerialHandler version 1.0a2
Roger Brown
Serialhandler is a HyperCard XFCN that opens access to the Macintosh serial ports. Several functions are available through the one handler. Each is specified by an opcode in the first parameter. Successive parameters and the return value depend on the opcode.
OPCODE INPUT DEFAULT OUTPUT
======= ===== ======= =======
"open " port (A,B) A = modem error messages
baud (300-9600) 9600 if any, or a handle
data bits (5-8) 8 to the input buffer if
parity (odd,even,none) none one larger than 64
stop bits (1,1.5,2) 1 bytes is requested
flow control
(XON/XOFF,CTS) XON/XOFF
input buffer size 64 bytes
"close" port (A,B) A = modem none
input buffer (optional)
"put" port (A,B) A = modem error messages
source of characters none
"get" port (A,B) A = modem error messages if any,
timeout (ticks) 30 (1/2 sec) or characters received
INVOKING SerialHandler
get SerialHandler(task,port,...)
where task is the opcode: open,close,put,or get
port is the port to use
... other parameters as in the table above
EXAMPLES
1. Opening with no parameters beyond the opcode will give you the defaults.
ex. get SerialHandler("open")
2. If you want an input buffer larger than 64 bytes then you must declare a global
variable to be used for only this purpose. Assign the return result of the open call
to this global. It will be locked until you close the serial port.
ex. On OpenPort
global serialBuffer -- declare the global here
put SerialHandler("open","A","4800,8,none,1,CTS,1024) into serialBuffer
-- open the port and assign a 1024 byte buffer which is global serialBuffer
if serialBuffer is not empty then put serialBuffer -- show any error message
end OpenPort
on ClosePort
global serialBuffer
get SerialHandler("close","A",serialBuffer) -- close port, set the input buffer
-- size to zero and unlock it
end closePort
3. When getting characters from the port, the timeout parameter is the minimum time
that SerialHandler will wait for input. If there are still characters to be read at the
end of the timeout period, SerialHandler will keep on reading until there are no more
to be read.
ex. put SerialHandler("get","A",60) into charsRecieved
4. get Serialhandler("put","A",the script of this stack) will send the text of the script
out serial port A, assuming it has been opened.
REVISION HISTORY
1.0a0 7/5/88 alpha release
1.0a1 7/11/88 mistake in GetSerialChars - 1st call to SetGetBuff had AinRefNum
instead of port as input
1.0a2 12/9/88 Call to ResultIs with an empty string was leaving orphan handles in the
heap. Also, changed for compilation under LSC 3.0.
-- part contents for card part 8
----- text -----
Alas, this demonstration will show you
nothing of interest unless you have a
serial device attached to the modem port
of your Mac. Like an Imagewriter, or a
terminal if you want to get input.
-- part contents for card part 12
----- text -----
Source not in the public domain, sorry.
-- part contents for card part 11
----- text -----
Characters received on the serial port will appear below: